package com.industrial.operation.controller;

import java.io.IOException;
import java.security.Security;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.industrial.common.core.utils.ServletUtils;
import com.industrial.common.core.utils.StringUtils;
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationEconomic;
import com.industrial.operation.service.IOperationEconomicService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 各市经济运行Controller
 * 
 * @author Zhou_S
 * @date 2024-01-17
 */
@RestController
@RequestMapping("/economic")
public class OperationEconomicController extends BaseController
{
    @Autowired
    private IOperationEconomicService operationEconomicService;



    @GetMapping("/groupMonth")
    public TableDataInfo groupMonth(String yearMonth)
    {
        startPage();

        if(StringUtils.isNotBlank(yearMonth)){
            yearMonth=yearMonth+"-01";
        }
        List<OperationEconomic> list = operationEconomicService.groupMonth(yearMonth);
        return getDataTable(list);
    }

    @GetMapping("/groupRegion")
    public AjaxResult groupRegion(String yearMonth)
    {
        startPage();
        List<OperationEconomic> list = operationEconomicService.groupRegion(yearMonth);
        return success(list);
    }


    /**
     * 查询各市经济运行列表
     */
    @RequiresPermissions("economic:economic:list")
    @GetMapping("/list")
    public TableDataInfo list(OperationEconomic operationEconomic)
    {
        startPage();
        List<OperationEconomic> list = operationEconomicService.selectOperationEconomicList(operationEconomic);
        return getDataTable(list);
    }

    /**
     * 导出各市经济运行列表
     */
    @RequiresPermissions("economic:economic:export")
    @Log(title = "各市经济运行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, String yearMonth)
    {

        if(StringUtils.isNotBlank(yearMonth)){
        AjaxResult.warn("未指定日期！");
        }
        List<OperationEconomic> list = operationEconomicService.groupRegion(yearMonth);
        ExcelUtil<OperationEconomic> util = new ExcelUtil<OperationEconomic>(OperationEconomic.class);
        util.exportExcel(response, list, "各市经济运行数据");
    }

    /**
     * 获取各市经济运行详细信息
     */
    @RequiresPermissions("economic:economic:query")
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        return success(operationEconomicService.selectOperationEconomicByBaseId(baseId));
    }

    /**
     * 新增各市经济运行
     */
    @RequiresPermissions("economic:economic:add")
    @Log(title = "各市经济运行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationEconomic operationEconomic)
    {
        return toAjax(operationEconomicService.insertOperationEconomic(operationEconomic));
    }

    /**
     * 修改各市经济运行
     */
    @RequiresPermissions("economic:economic:edit")
    @Log(title = "各市经济运行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationEconomic operationEconomic)
    {
        return toAjax(operationEconomicService.updateOperationEconomic(operationEconomic));
    }

    /**
     * 删除各市经济运行
     */
    @RequiresPermissions("economic:economic:remove")
    @Log(title = "各市经济运行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationEconomicService.deleteOperationEconomicByBaseIds(baseIds));
    }



    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<OperationEconomic> util = new ExcelUtil<OperationEconomic>(OperationEconomic.class);
        List<OperationEconomic> userList = util.importExcel(file.getInputStream());

        String operName = SecurityUtils.getUsername();

       /* String message = userService.importUser(userList, updateSupport, operName);*/
        return AjaxResult.success(userList);
    }

}
